<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Post_trip extends CI_Controller {
	
	

		
	public function index(){
		$this->load->helper('form');
		$this->load->helper('file');
		$this->load->helper('url');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->form_validation->set_rules('from','from', 'required');
		$this->form_validation->set_rules('to','to', 'required');
		$this->form_validation->set_rules('max','max', 'required|is_natural');
		$this->form_validation->set_rules('year','year');
		$this->form_validation->set_rules('month','month');
		$this->form_validation->set_rules('day','day');
		$this->form_validation->set_rules('time','time');
		if($this->form_validation->run() == FALSE){
			
			$this->load->view('post_trip_view');
		
		} else {
			
			$from = $this->input->post('from');
			$to = $this->input->post('to');
			$max = $this->input->post('max');
			$year = $this->input->post('year');
			$month = $this->input->post('month');
			$day = $this->input->post('day');
			$time = $this->input->post('time');
			$driver = $this->input->post('driver');
			$user = $this->session->userdata('user_id');
			$this->load->model('post_trip_model');
			$local = $this->post_trip_model->post_trip($from,$to,$max,$year,$month,$day,$time,$driver,$user);
			$path = "postings/"."$local".".php";
			$data = 'test';
			$fp = fopen($path,"wb");
			fwrite($fp,$data);
			fclose($fp);
			redirect('http://redwolf.cdf.toronto.edu:8830/ci/index.php/main'); 
		}
	}

}
?>